# include "scene.h"
# include <stdio.h>
# include <stdlib.h>
# include <math.h>

extern void print_grid_conf(struct grid_config *gc, struct grid *g)
  {
   FILE *ptr;
   short isec, izone;

   ptr = g->lptr;

#ifdef CHECK_CONFIG
top:
#endif

# ifdef READ_GRID_FILES
   fprintf(ptr, "\n\n\t<<======[ ['r-grid' parameters] ]======>>\n");
   for(isec = 0; isec < Nsec; isec++) fprintf(ptr, "nr.%d = %d\n", isec+1, g->nr[isec]);
   fprintf(ptr, "nr_nozzle = %d\nnr_gap = %d\nNrG = %d\n", g->nr_nozzle, g->nr_gap, NrG);

   fprintf(ptr, "\n\n\t<<======[ ['th-grid' parameters] ]======>>\n");
   fprintf(ptr, "nth = %d\n", g->nth);
   fprintf(ptr, "NthG = %d\n", NthG);

   fprintf(ptr, "\n\n\t<<======[ ['z-grid' parameters] ]======>>\n");
   for(isec = 0; isec < Nsec; isec++) fprintf(ptr, "nz.%d = %d\n", isec+1, g->nz[isec]);
   fprintf(ptr, "NzG = %d\n", NzG);

# else

   fprintf(ptr, "\n\n\t<<======[ ['r-grid' parameters] ]======>>\n");

#  ifdef r_UNIF_GRID
   fprintf(ptr, "dr: %E\n", g->dr);
#  else
   for(isec = 0; isec < Nsec; isec++)
      {
       fprintf(ptr, "\n\n\t[ SECTION - %d ]\n", isec);
       fprintf(ptr, "\n**Total number of grids ---> %d\n\n", g->nr[isec]);

       for(izone = 0; izone < gc[isec].nzone_r; izone++)
         fprintf(ptr, "=== Zone No.%d === \n\tr: %E ~ %E\n\tdr: %E ~ %E\n\tr_cd: %E\n\t**nr: %d\n\n",
         izone, gc[isec].r[izone], gc[isec].r[izone+1], gc[isec].dr[izone], gc[isec].dr[izone+1], gc[isec].r_cd[izone], gc[isec].nr[izone]);
      }
#  endif

   fprintf(ptr, "\n\n\t<<======[ ['th-grid' parameters] ]======>>\n\n");

#  ifdef th_UNIF_GRID
   fprintf(ptr, "**Total number of grids = %d\n", g->nth);
   fprintf(ptr, "d_theta:\n\tIn 'degrees': %E\n\tIn 'radians': %E\n", 90*g->dth/acos(0), g->dth);
   fprintf(ptr, "\nZone-extension:\n\tIn 'degrees': %E\n\tIn 'radians': %E\n", g->nth*90*g->dth/acos(0), g->nth*g->dth);
#  else
   fprintf(ptr, "ERROR:: in 'print_grid_conf()': incomplete definition for non-uniform grids in thera direction. Exiting the program.\n");
   exit(-1);
#  endif

   fprintf(ptr, "\n\n\n\t<<======[ ['z-grid' parameters] ]======>>\n");

#  ifdef z_UNIF_GRID
   fprintf(ptr, "\ndz: %E ---> %E\n", dZ, g->dz[1]);
   fprintf(ptr, "**nz ---> %d\n\n", g->nz[0]);

#  else

   for(isec = Nsec-1; isec >= 0; isec--)
      {
       fprintf(ptr, "\n\n\t[ SECTION - %d ]\n", isec);

       fprintf(ptr, "\n**Total number of grids ---> %d\n\n", g->nz[isec]);

       for(izone = gc[isec].nzone_z-1; izone >= 0; izone--)
       fprintf(ptr, "=== Zone No.%d ===\n\tz: %E ~ %E\n\tdz: %E ~ %E\n\tz_cd: %E\n\t**nz: %d\n\n",\
          izone, gc[isec].h[izone], gc[isec].h[izone+1], gc[isec].dh[izone], gc[isec].dh[izone+1], gc[isec].h_cd[izone], gc[isec].nz[izone]);
      }

#  endif

# endif

#  ifdef CHECK_CONFIG
   if(ptr != stdout)
       {
        ptr = stdout;
        goto top;
       }
   else{
        fprintf(ptr, "\n\tAre the parameters reasonable (y/n) ? ");  fflush(ptr);
        if(getchar() != 'y')
           {
            fprintf(ptr, "\nWARNING:: in 'print_grid_conf()': Re-define the grid-configuration parameters in \"scene.h\", re-compine, and then run the program again.\nExiting...\n");
            exit(-1);
           }
        else while(getchar() != '\n');
        ptr = g->lptr;
       }
#  endif

   return;
  }
